package com.lfy.modules.scheduler.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
/**
 *  防止调度器因未知错误关闭
 *
 * @author <a href="https://www.lvfeiy.top">lvfeiyang</a>
 * @date 2024/4/25 1:00
 */
@Aspect
@Component
@Slf4j
public class SchedulerAccept {
    @Resource
    private Scheduler scheduler;
    @Pointcut("within( com.lfy.modules.scheduler.controller.TaskController)")
    public void cut(){

    }
    @Before("cut()")
    public void before(){
        try {
            if(scheduler.isShutdown()){
                scheduler.start();
            }
        } catch (SchedulerException e) {
            log.error("scheduler is shutdown",e);
        }
    }

}
